const util = require('../../utils/util.js');
var api = require('../../config/api.js');
//获取应用实例
const app = getApp();
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoad: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    /*
    app.postForm(api.sendScene, { scene: JSON.stringify(options)}).then(rsp => {
      util.confirm.modal(rsp.errmsg);
    });*/
    var scene = options.scene;
    if (!util.isNullOrEmpty(scene)) {
      scene = decodeURIComponent(scene); //与房东绑定的唯一序列号
      //检测房东二维码唯一标识是否绑定成功 pages/QrBind/index
      app.postForm(api.CheckBindQr, { scene:scene }, { retry: 3, isAllow: true }).then(rsp => {
        if (util.isNullOrEmpty(rsp.data.homeownersNo)){
          wx.redirectTo({
            url: '/pages/QrBind/bind?serial=' + scene,
          })
        }else{
          wx.redirectTo({
            url: '/pages/houseRes/share/index?id=' + rsp.data.homeownersNo,
          })
        }
      });
    } else {
      that.setData({ isLoad: false });
      util.confirm.modalOk('扫码异常!',function(){
        that.exit();
      });
    }
  },
  exit(){
    wx.reLaunch({
      url: '/pages/index/index?finish=true',
    });
  },
  jumpToOther(scene) {
    util.toast.loading('正在跳转中...');
    wx.navigateToMiniProgram({
      appId: app.relevanceA.appId,
      path: app.relevanceA.path + '?id=' + app.globalData.ownerNo,
      extraData: { scene: encodeURIComponent(app.globalData.ownerNo) },
      envVersion: app.relevanceA.envVersion,
      success(res) {
        console.log('success');
        console.log(res)
      },
      fail(res) {
        that.setData({ isLoad: false });
        util.toast.fail('跳转失败');
        setTimeout(function () {
          wx.navigateBack({
            delta: -1
          })
        }, 1000);
        console.log(res);
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})